package com.appointment.validation;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;

import java.util.List;

public class ValueInListValidator implements ConstraintValidator<ValueInList, Object> {

    private List<String> values;

    @Override
    public void initialize(ValueInList constraintAnnotation) {
        this.values = List.of(constraintAnnotation.values());
    }

    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        if (value == null) {
            return false;
        }
        return values.contains(value.toString());
    }
}
